/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package struts;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import test.Test;

/**
 *
 * @author Alex
 */
public class GetListeAction extends ActionSupport
{
    Test testBean = lookupTestBeanRemote();
    private List<String> liste;

    public List<String> getListe() {
        return liste;
    }


    @Override
    public String execute()
    {
        Test leTest = (Test) ActionContext.getContext().getSession().get("ejb");
        
        if(leTest == null)
        {
            ActionContext.getContext().getSession().put("ejb", testBean);
            leTest = testBean;
        }

        liste = leTest.getList();
        

        return SUCCESS;
        
    }

    private Test lookupTestBeanRemote() {
        try {
            Context c = new InitialContext();
            return (Test) c.lookup("test.Test");
        } catch (NamingException ne) {
            Logger.getLogger(getClass().getName()).log(Level.SEVERE, "exception caught", ne);
            throw new RuntimeException(ne);
        }
    }
}
